package com.pro.start;

import com.pro.service.RegisterClientService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Copyright C 四川众鹏科技有限公司
 * All right reserved.  ServiceRenewal
 * 创建者：aoneng 2022/9/19
 * Description: 服务续约，定时像服务端发送续约请求
 * 备注   :
 * version:  V1.0
 * <author> - <version > - <time>  -    <desc>
 *
 * @author 敖能         V1.0       2022/9/19    完成基本功能
 */
public class ServiceRenewal {
    private ScheduledExecutorService scheduledService = Executors.newSingleThreadScheduledExecutor();
    private static final Log log = LogFactory.getLog(ServiceRenewal.class);
    /**
     * 客户端服务续约线程什么时候启动？
     * 服务注册完成之后
     */
    public void serviceRenewalStart() {
        log.info("服务续约线程启动...");
        scheduledService.scheduleAtFixedRate(new ServiceRenewalThread(), 3, 3, TimeUnit.SECONDS);
    }

    @Autowired
    private RegisterClientService registerServiceS;
    /**
     * 服务续约线程
     */
    class ServiceRenewalThread implements Runnable {
        @Override
        public void run() {
            registerServiceS.renewal();
        }
    }
}
